package com.fingard.dsp.bank.directbank.psbc01;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.ITransaction;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7515TodayTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.RetAtsTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.detail.RetAtsTransDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fujia
 * @description 实现查询银行明细、交易流水报文转发、接收、解析
 * @time 20160825
 */
public class PSBC01Transaction extends PSBC01Base implements ITransaction {

    /**
     * 返回ats银行明细报文
     */
    public RetAtsTrans d_7516_HisTrans(Req7516HisTrans p_req7516) throws Exception {
        Map<String, RetAtsTransDetail> map = new HashMap<String, RetAtsTransDetail>();//记录已查询明细，防重
        //历史明细查询返回ATS的对象
        RetAtsTrans retAts = new RetAtsTrans(p_req7516.reqHeader);
        String tmpRespCode = "";
        String tmpRespInfo = "";
        retAts.writeStart();//写返回ATS的统一头部信息
        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());

            int tmpIntDateFrom = 0;
            int tmpIntDateTo = 0;
            //按自然月循环查询
            while (tmpIntDateFrom <= tmpIntDateTo && tmpRespCode.length() == 0) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                //判断是否跨月
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {
                    //跨月则设置为月末
                    tmpClndrStepTo.set(Calendar.DAY_OF_MONTH, tmpClndrStepTo.getActualMaximum(Calendar.DAY_OF_MONTH));
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");//设置日期格式
                PSBC01Header bankHeader = new PSBC01Header();
                bankHeader.OpName = "2108";
                bankHeader.Outsys_Code = "ats";
                bankHeader.OpDate = df.format(new Date()) + "";
                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                //写入通用的头部节点
                writeCommonHeader(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("Param");
                xmlWriter.writeElementString("Query_Account", p_req7516.actNum);
                xmlWriter.writeElementString("Begin_Date", Format.Date8Format.format(tmpCalendarFrom.getTime()));
                xmlWriter.writeElementString("End_Date", Format.Date8Format.format(tmpClndrStepTo.getTime()));
                xmlWriter.writeElementString("Reserved1", "0");
                xmlWriter.writeElementString("Reserved2", "0");
                xmlWriter.writeElementString("Reserved3", "0");
                xmlWriter.writeElementString("Reserved4", "0");
                xmlWriter.writeEndDocument();

                //测试代码：打印报文
                //System.out.println("xmlWriter.toXmlString():\n"+xmlWriter.toXmlString());
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//                String[] tmpStrRet = new String[]{"", "<?xml version= \"1.0\" encoding=\"GBK\"?>\n" +
//                        "<root>\n" +
//                        "    <Head>\n" +
//                        "        <OpName></OpName>\n" +
//                        "        <OpRetCode>00</OpRetCode>\n" +
//                        "        <OpRetMsg>交易成功</OpRetMsg>\n" +
//                        "    </Head>\n" +
//                        "    <Param>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>测试姓名010001</Name>\n" +
//                        "            <Account>100002668890010001</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司北京分行直属支行</Bank>\n" +
//                        "            <Bank_Id>403100004499</Bank_Id>\n" +
//                        "            <Amount>100000</Amount>\n" +
//                        "            <Balance>88916834607</Balance>\n" +
//                        "            <Flag>1</Flag>\n" +
//                        "            <Bank_Serial>31194168</Bank_Serial>\n" +
//                        "            <EnterpriseID>20190104000000000011</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>072046</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>资金上划</Usage>\n" +
//                        "            <Remark>资金上划</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053119416800200</Reserved2>\n" +
//                        "            <Reserved3></Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>DVP上清1901ST0002</Name>\n" +
//                        "            <Account>100000225111</Account>\n" +
//                        "            <Bank>银行间市场清算所</Bank>\n" +
//                        "            <Bank_Id>909290000007</Bank_Id>\n" +
//                        "            <Amount>1500</Amount>\n" +
//                        "            <Balance>88916833107</Balance>\n" +
//                        "            <Flag>0</Flag>\n" +
//                        "            <Bank_Serial>31195218</Bank_Serial>\n" +
//                        "            <EnterpriseID></EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>151206</Trans_Time>\n" +
//                        "            <Tx_Flag>大额</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>,88</Usage>\n" +
//                        "            <Remark></Remark>\n" +
//                        "            <Chnl_Code>托管系统</Chnl_Code>\n" +
//                        "            <Reserved1>38</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053119521800100</Reserved2>\n" +
//                        "            <Reserved3></Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>测试姓名595555</Name>\n" +
//                        "            <Account>915001010000595555</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司呼和浩特市金桥支行</Bank>\n" +
//                        "            <Bank_Id>403191007426</Bank_Id>\n" +
//                        "            <Amount>7000000</Amount>\n" +
//                        "            <Balance>88909833107</Balance>\n" +
//                        "            <Flag>0</Flag>\n" +
//                        "            <Bank_Serial>31214450</Bank_Serial>\n" +
//                        "            <EnterpriseID>20200111xxxx0006</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>100228</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>ceshi001</Usage>\n" +
//                        "            <Remark>ceshi002</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053121445000100</Reserved2>\n" +
//                        "            <Reserved3></Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>测试姓名010001</Name>\n" +
//                        "            <Account>100002668890010001</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司北京分行直属支行</Bank>\n" +
//                        "            <Bank_Id>403100004499</Bank_Id>\n" +
//                        "            <Amount>150000</Amount>\n" +
//                        "            <Balance>88909983107</Balance>\n" +
//                        "            <Flag>1</Flag>\n" +
//                        "            <Bank_Serial>31419753</Bank_Serial>\n" +
//                        "            <EnterpriseID>20190105000000000012</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>032018</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>资金上划</Usage>\n" +
//                        "            <Remark>资金上划</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053141975300200</Reserved2>\n" +
//                        "            <Reserved3></Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>测试姓名010001</Name>\n" +
//                        "            <Account>100002668890010001</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司北京分行直属支行</Bank>\n" +
//                        "            <Bank_Id>403100004499</Bank_Id>\n" +
//                        "            <Amount>180000</Amount>\n" +
//                        "            <Balance>88910163107</Balance>\n" +
//                        "            <Flag>1</Flag>\n" +
//                        "            <Bank_Serial>31449766</Bank_Serial>\n" +
//                        "            <EnterpriseID>20190105000000000013</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>054134</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>资金上划</Usage>\n" +
//                        "            <Remark>资金上划</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053144976600200</Reserved2>\n" +
//                        "            <Reserved3></Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>唐僧</Name>\n" +
//                        "            <Account>6210986500000031654</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司四川省分行直属支行</Bank>\n" +
//                        "            <Bank_Id>5199821Q</Bank_Id>\n" +
//                        "            <Amount>11100</Amount>\n" +
//                        "            <Balance>88910152007</Balance>\n" +
//                        "            <Flag>0</Flag>\n" +
//                        "            <Bank_Serial>31463308</Bank_Serial>\n" +
//                        "            <EnterpriseID>000000T5</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>064511</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>对账码测试＋</Usage>\n" +
//                        "            <Remark>CC000000TB</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053146330800200</Reserved2>\n" +
//                        "            <Reserved3>1311</Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "        <RecordSet>\n" +
//                        "            <Cust_Acct>100286869440010001</Cust_Acct>\n" +
//                        "            <Acct_Name>测试姓名010001</Acct_Name>\n" +
//                        "            <Name>唐僧</Name>\n" +
//                        "            <Account>6210986500000031654</Account>\n" +
//                        "            <Bank>中国邮政储蓄银行股份有限公司四川省分行直属支行</Bank>\n" +
//                        "            <Bank_Id>5199821Q</Bank_Id>\n" +
//                        "            <Amount>22200</Amount>\n" +
//                        "            <Balance>88910129807</Balance>\n" +
//                        "            <Flag>0</Flag>\n" +
//                        "            <Bank_Serial>31466162</Bank_Serial>\n" +
//                        "            <EnterpriseID>000000T6</EnterpriseID>\n" +
//                        "            <Trans_Date>20190105</Trans_Date>\n" +
//                        "            <Trans_Time>065846</Trans_Time>\n" +
//                        "            <Tx_Flag>行内</Tx_Flag>\n" +
//                        "            <Vchr_type></Vchr_type>\n" +
//                        "            <Vchr_No></Vchr_No>\n" +
//                        "            <Usage>对账码测试＋</Usage>\n" +
//                        "            <Remark>CC000000TC</Remark>\n" +
//                        "            <Chnl_Code>企业金融系统</Chnl_Code>\n" +
//                        "            <Reserved1>50</Reserved1>\n" +
//                        "            <Reserved2>0000317362201901053146616200200</Reserved2>\n" +
//                        "            <Reserved3>1311</Reserved3>\n" +
//                        "            <Reserved4></Reserved4>\n" +
//                        "        </RecordSet>\n" +
//                        "    </Param>\n" +
//                        "</root>\n"};

                XmlTextReader tmpBkReader;
                /*测试报文开始
				String[] tmpStrRet ={"",""};
				tmpStrRet[0]="";
				tmpStrRet[1]="<?xml version=\"1.0\" encoding = \"GBK\"?><root><Head><OpName>2108</OpName><OpRetCode>00</OpRetCode><OpRetMsg></OpRetMsg></Head><Param><RecordSet><Cust_Acct>0943340304343</Cust_Acct>"
				+"<Acct_Name>张福佳</Acct_Name><Name>李四</Name><Account>3884399434</Account><Bank>212</Bank><Bank_Id>032303</Bank_Id><Amount>200000</Amount><Balance>10000</Balance>"
				+"<Flag>0</Flag><Bank_Serial>2121212</Bank_Serial><EnterpriseID>0245500323</EnterpriseID><Trans_Date>20150403</Trans_Date><Trans_Time>132434</Trans_Time><Tx_Flag></Tx_Flag><Vchr_Type/><Vchr_No></Vchr_No><Usage>赔款</Usage>"
				+"<Remark>10000002320</Remark><Chnl_Code></Chnl_Code><Reserved1></Reserved1><Reserved2></Reserved2><Reserved3></Reserved3><Reserved4>300002323</Reserved4>"
				+"</RecordSet><RecordSet><Cust_Acct>0943340304343</Cust_Acct><Acct_Name>12122</Acct_Name><Name>12122</Name><Account>3884399434</Account><Bank>12122</Bank><Bank_Id>032303</Bank_Id>"
				+"<Amount>200000</Amount><Balance>10000</Balance><Flag>0</Flag><Bank_Serial>2121212</Bank_Serial><EnterpriseID>0245500323</EnterpriseID><Trans_Date>20150403</Trans_Date>"
				+"<Trans_Time>132434</Trans_Time><Tx_Flag></Tx_Flag><Vchr_Type/><Vchr_No></Vchr_No><Usage>2122</Usage><Remark>10000002320</Remark><Chnl_Code></Chnl_Code>"
				+"<Reserved1></Reserved1><Reserved2></Reserved2><Reserved3></Reserved3><Reserved4>0121142010024</Reserved4></RecordSet></Param></root>";
				*///测试报文结束
                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String retCode = tmpBkReader.getFirstText("/root/Head/OpRetCode");
                        String retMsg = tmpBkReader.getFirstText("/root/Head/OpRetMsg");
                        if (retCode.equals("00"))//返回00表示查询成功，可以继续后续数据处理
                        {
                            if (!retAts.hasWrittenRespCode) {
                                retAts.writeRespInfo(retMsg);
                            }
                            //提取RecordSet中各节点内容
                            while (tmpBkReader.read("/root/Param/RecordSet")) {
                                RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                XElement tmpRetNode = tmpBkReader.readedXElement;
                                String dealDate = tmpRetNode.getSingleText("Trans_Date");
                                String dealTime = tmpRetNode.getSingleText("Trans_Time");
                                tmpRetDetail.tranDate = DateHelper.getFormat12Date(dealDate);//格式yyyy-MM-dd
                                tmpRetDetail.valueDate = tmpRetDetail.tranDate;//格式yyyy-MM-dd
                                tmpRetDetail.tranTime = tmpRetDetail.tranDate + " " + DateHelper.getFormat8Time(dealTime);//格式"yyyy-MM-dd HH:mm:ss"
                                //tmpRetDetail.tranTime = tmpRetDetail.tranDate + " " + dealTime.substring(0, 2) + ":" + dealTime.substring(2, 4) + ":" + dealTime.substring(4);
                                // 提取摘要、备注，摘要和备注中有一个字段含有对账码，通过提取方法获取对账码
//                                tmpRetDetail.comment = tmpRetNode.getSingleTextNotNull("postScript").trim();
                                //ATSES-22232 通威目前在用的十个支付渠道,对账码识别截取优化-----范天星/2020/01/19
                                String memo = tmpRetNode.getSingleTextNotNull("Usage").trim();
                                if (memo.contains("＋")) {
                                    tmpRetDetail.comment = memo.substring(0, memo.lastIndexOf("＋"));
                                    tmpRetDetail.usage = memo.substring(0, memo.lastIndexOf("＋"));
                                    tmpRetDetail.abstr = tmpRetNode.getSingleTextNotNull("Remark").trim();
                                } else {
                                    tmpRetDetail.comment = tmpRetNode.getSingleText("Remark");
                                    tmpRetDetail.usage = memo;
                                    tmpRetDetail.abstr = "";
                                }
//                                tmpRetDetail.usage = tmpRetNode.getSingleTextNotNull("Usage").trim();
//                                tmpRetDetail.abstr = pickupAbstr(tmpRetNode.getSingleTextNotNull("Reserved4"), tmpRetDetail.usage, tmpRetDetail.comment);
                                tmpRetDetail.actNum = tmpRetNode.getSingleTextNotNull("Cust_Acct").trim();
                                tmpRetDetail.recAccBank = tmpRetNode.getSingleTextNotNull("Bank").trim();
                                tmpRetDetail.recAccNum = tmpRetNode.getSingleTextNotNull("Account").trim();
                                tmpRetDetail.recAccName = tmpRetNode.getSingleTextNotNull("Name").trim();
                                tmpRetDetail.payCode = tmpRetNode.getSingleTextNotNull("Reserved4").trim();//??
                                tmpRetDetail.askNumber = tmpRetNode.getSingleTextNotNull("EnterpriseID").trim();
                                tmpRetDetail.reqBatchNO = tmpRetNode.getSingleTextNotNull("Bank_Serial").trim();
                                //空指针过滤，如果获取的字符串不为空，则执行强制转换
                                if (null != tmpRetNode.getSingleText("Balance") && !"".equals(tmpRetNode.getSingleText("Balance"))) {
                                    tmpRetDetail.accBal = StringHelper.amountDivide100(tmpRetNode.getSingleText("Balance"));
                                    //tmpRetDetail.accBal = Integer.parseInt(tmpRetNode.getSingleText("Balance")) / 100 + "";
                                }
                                //空指针过滤，如果获取的字符串不为空，则执行强制转换
                                if (null != tmpRetNode.getSingleText("Amount") && !"".equals(tmpRetNode.getSingleText("Amount"))) {
                                    tmpRetDetail.tranAmt = StringHelper.amountDivide100(tmpRetNode.getSingleText("Amount"));
//                                    tmpRetDetail.tranAmt = Integer.parseInt(tmpRetNode.getSingleText("Amount")) / 100 + "";//交易金额
                                }
                                //银行返回借贷标志 0-借 1-贷"，dsp返回资金系统1-借 2贷
                                String Flag = tmpRetNode.getSingleText("Flag");//正负标志
                                tmpRetDetail.cdFlag = (Flag.equals("0")) ? ("1") : ("2");
                                //防重操作
                                if (map.get(tmpRetDetail.reqBatchNO) != null) {
                                    if(map.get(tmpRetDetail.reqBatchNO).accBal.equals(tmpRetDetail.accBal)
                                            && map.get(tmpRetDetail.reqBatchNO).tranAmt.equals(tmpRetDetail.tranAmt)){
                                        continue;
                                    }else {
                                        map.put(tmpRetDetail.reqBatchNO, tmpRetDetail);
                                    }
                                } else {
                                    map.put(tmpRetDetail.reqBatchNO, tmpRetDetail);
                                }
                                retAts.writeRetDetail(tmpRetDetail);
                            }
                        } else {
                            //  "查询失败"
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpBkReader.getFirstText("/root/Head/OpRetMsg");
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpStrRet[1];
                }
                tmpCalendarFrom = tmpClndrStepTo;
                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpCalendarFrom.getTime()));
                tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()));
            }
        } catch (Exception e) {
            tmpRespCode = "-1";
            tmpRespInfo = e.getMessage();
            e.printStackTrace();
        }
        if (tmpRespCode.equals("-1")) {
            retAts = new RetAtsTrans(p_req7516.reqHeader);
            retAts.writeStart();//写返回ATS的统一头部信息
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            if (!retAts.hasWrittenRespCode) {
                retAts.writeRespCode("0");
            }
            if (!retAts.hasWrittenRespInfo) {
                retAts.writeRespInfo("查询结果为空");
            }
        }
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 查询历史明细
     */
    public RetAtsTrans d_7515_TodayTrans(Req7515TodayTrans p_req7515) throws Exception {
        Req7516HisTrans tmpReq7516 = new Req7516HisTrans(p_req7515.reqHeader);
        tmpReq7516.actArea = p_req7515.actArea;
        tmpReq7516.actCur = p_req7515.actCur;
        tmpReq7516.actNum = p_req7515.actNum;
        String tmpStrToday = Format.Date8Format.format(new Date());
        tmpReq7516.dateFrom = tmpStrToday;//设置开始时间和结束时间都为当天
        tmpReq7516.dateTo = tmpStrToday;
        return d_7516_HisTrans(tmpReq7516);
    }
}
